Conversation
| app: typing.Callable = None, | ||
| raise_app_exceptions: bool = True, | ||
| backend: ConcurrencyBackend = None, | ||
| additional_middlewares: list = None, # TODO: is this the best way to inject mws? |
There was a problem hiding this comment.
Can we rename this param to just middlewares?
There was a problem hiding this comment.
I considered it but thought it might convey that you can override the built-in middlewares so I added the "additional". Happy to change it if we don't think that's the case.
| raise TooManyRedirects() | ||
| if request.url in [response.url for response in history]: | ||
| raise RedirectLoop() | ||
| for middleware in middlewares: |
There was a problem hiding this comment.
In order to implement caching we'd need a middleware to be able to return an HTTP response on the process_request() stage.
There was a problem hiding this comment.
Good point, is it worth adding it now?
There was a problem hiding this comment.
I think so, might as well get it working with this revision.
|
Definitely want your thoughts on this @tomchristie |
|
Ping @tomchristie I think this interface is really promising. |
|
I'm still not really sure at the moment. There's a couple different styles we could use, one is a separate Another option would be a single callable or method, that is passed a request, and the next callable... async def middleware(request, call_next):
# Do some request processing
response = await call_next(request)
# Do some response processingI think it's a bit awkward that we're having to set up a middleware chain per-request. The other thing that ties in here is our existing dispatch interface. The I'd probably need to make a separate PR to show how that'd look, and why it ties in to me now being sure exactly what we should (or shouldn't) do about a middleware interface. |
|
Apologies for not being able to be more definitive yet. |
|
No worries, that's why I put together this PR, so we can think about it and discuss it. 🙂
I agree. The reason it's that way is because we allow Ideally we'd build the necessary middlewares once on the initializer, but we'd have to break the
That's interesting, we would avoid introducing a new abstraction at the cost of building the chain from the set of arguments. I think I'll have a go at this and open up a different PR from what's on this one. |
|
Closed in favor of #268 |
Split from #136 as requested. Also from that PR with some changes:
A stab at refactoring redirects and auth into middlewares. Quick tests using httpbin seems to work for redirects and basic auth, a digest auth is also working but not included in this PR.
The main idea is:
client.sendsets up the pipelineI've inlined some comments in the problematic areas but main ones are:
response.nextwas assembled as a callable inside the loop, which by refactoring into the middleware makes it much harder so I temporarily left it broken.Hopefully with this PR is a bit clearer and we can discuss design options 🙂